# -*- coding: utf-8 -*-

# dialogs/plugin.py

# Copyright 2009-2010 Diego Hansen Hahn (aka DiegoHH) <diegohh90 [at] hotmail [dot] com>

# lazynds is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.

# lazynds is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with lazynds. If not, see <http://www.gnu.org/licenses/>.


class Plugin:
    def __init__(self, builder, parent, info):
        self.builder = builder
        self.dialog = self.builder.get_object('plugin_dialog')
        self.dialog.set_transient_for(parent)

        self.treeview = self.builder.get_object('plg_treeview')
        self.treeview.connect('cursor-changed', self.on_cursor_changed)

        self.info = info
        self.liststore = self.builder.get_object('plg_liststore')

        self.plg_name = self.builder.get_object('plg_name')
        self.plg_description = self.builder.get_object('plg_description')
        self.plg_authors = self.builder.get_object('plg_authors')
        self.plg_website = self.builder.get_object('plg_website')

        for x in self.info:
            self.liststore.append([x['Module']])

    def on_cursor_changed(self, widget):
        index =  widget.get_cursor()[0][0]
        self.plg_name.set_text(self.info[index]['Name'])
        self.plg_description.set_text(self.info[index]['Description'])
        self.plg_authors.set_text(self.info[index]['Authors'])
        self.plg_website.set_text(self.info[index]['Website'])

    def run(self):
        self.dialog.run()

        self.dialog.hide()

        return True





